const express = require('express')
const { User } = require('../models/user')

const router = express.Router()

router.post('/add', express.json(), async (req, res) => {
  const user = await User.create(req.body)
  res.send({ code: 0, msg: 'ok', data: user.toJSON() })
})

router.get('/list', async (req, res) => {
  const users = await User.findAll()
  // console.log(users[0] instanceof User, 'hehe')
  // const articles = await users[0].getArticles();
  // console.log(articles.length, articles[0].toJSON(), 'hehe')
  // console.log((await users[0].getArticles())[0].toJSON(), 'hehe')
  
  res.send({ code: 0, msg: 'ok', data: users })
})

module.exports = {
  router
}
